package com.cloudlead.plugin.dict.service.impl;

import java.util.List;

import com.cloudlead.plugin.dict.BusinessModules;
import com.cloudlead.plugin.dict.entity.EDict;
import com.cloudlead.plugin.dict.repository.EDictRepository;
import com.cloudlead.plugin.dict.service.DictGroupService;
import com.cloudlead.plugin.dict.service.DictService;
import com.cloudlead.plugin.dict.vo.Dict;
import com.cloudlead.plugin.dict.vo.DictGroup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cloudlead.common.lang.DictData;
import com.cloudlead.common.lang.annotation.Label;
import com.cloudlead.common.lang.service.DictDataService;
import com.cloudlead.common.persistence.impl.AbstractMultiTableCrudService;

/**
 * DictServiceImpl is a Codegen service implement type
 */
@Label("字典服务实现")
@Service("dictService")
public class DictServiceImpl extends
        AbstractMultiTableCrudService<EDictRepository, Dict, EDict> implements
        DictService, DictDataService {

    @Autowired
    private DictGroupService dictGroupService;

    @Autowired
    public DictServiceImpl(EDictRepository repository) {
        super(BusinessModules.Dict, repository);
        this.hasCache = true;
    }

    @Override
    public List<? extends DictData> findDicts(String group) {
        DictGroup groupExample = new DictGroup();
        groupExample.setName(group);
        DictGroup dictGroup = dictGroupService.findOne(groupExample);
        Dict example = new Dict();
        example.setGroupId(dictGroup.getId());
        return this.list(example, null);
    }

}
